package com.service.user;

import com.common.ErrorCodeEnum;
import com.common.emums.DataStatus;
import com.common.exception.BusinessException;
import com.common.utils.MD5;
import com.common.utils.StringUtils;
import com.core.springSecurity.common.SecurityUtils;

import com.dao.primary.user.UserInfoMapper;
import com.model.domain.user.GetUserInfoDO;
import com.model.pojo.user.UserInfo;
import com.service.sys.SysUserService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import com.github.pagehelper.PageHelper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;



/**
 * @Author: zql
 * @Description: 【请填写功能名称】服务
 * @Data: 2023-08-26
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class UserInfoService {
    private final UserInfoMapper userInfoMapper;
    private final SysUserService sysUserService;
    public List<UserInfo> getPageList(GetUserInfoDO getUserInfoDO){
        PageHelper.clearPage();
        PageHelper.startPage(getUserInfoDO.getPage(),getUserInfoDO.getPageSize(),getUserInfoDO.getSortRow()+getUserInfoDO.getSortOrder());
        return userInfoMapper.selectList(getUserInfoDO);
    }

    public List<UserInfo> getAllList(GetUserInfoDO getUserInfoDO){
        PageHelper.clearPage();
        PageHelper.orderBy(getUserInfoDO.getSortRow()+getUserInfoDO.getSortOrder());
        return userInfoMapper.selectList(getUserInfoDO);
    }

    public UserInfo getById(long id){
        return userInfoMapper.selectByPrimaryKey(id);
    }
    public UserInfo getByCellphone(String cellphone){
        return userInfoMapper.selectByCellphone(cellphone);
    }

    public int update(UserInfo userInfo){
        return userInfoMapper.updateByPrimaryKeySelective(userInfo);
    }
    public UserInfo save(UserInfo userInfo){
        userInfo.setRegisterTime(new Date());
        userInfoMapper.insertSelective(userInfo);
        return userInfo;
    }
}
